/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metricmaster.gui.projecttab;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import metricmaster.model.Activity;

/**
 *
 * @author markblanda
 */
public class ActivitiesTableModel extends AbstractTableModel {
    private String[] columnNames = {"Shop Order", "Description", "Start", "Finish"};
    private ArrayList<Activity> activityData;
    
    public ActivitiesTableModel() {
        activityData = new ArrayList<>();
    }
    
    public ActivitiesTableModel(ArrayList<Activity> data) {
        activityData = data;
    }
    
    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public int getRowCount() {
        return activityData.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        return false;
    }
    
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Activity act = activityData.get(rowIndex);
        String value = "";
        switch (columnIndex) {
            case 0: value = act.getShopOrder();
                break;
            case 1: value = act.getDescription();
                break;
            case 2: value = act.getStart();
                break;
            case 3: value = act.getFinish();
                break;
        }
        return value;
    }

    /**
     * @return the activityData
     */
    public ArrayList<Activity> getActivityData() {
        return activityData;
    }

    /**
     * @param activityData the activityData to set
     */
    public void setActivityData(ArrayList<Activity> activityData) {
        this.activityData = activityData;
        fireTableDataChanged();
    }
    
    public void addActivity(Activity activity) {
        activityData.add(activity);
        fireTableDataChanged();
    }
}
